import com.yq.io.UFile;

import java.io.File;
import java.lang.String;
import java.util.ArrayList;

public class CheckFiles {
    public static final String source_dir = "/Volumes/Data/work/apache_root/files/Sanguo2_10_16_.085/assets/bin/Data";
    public static final String project_dir = "/Volumes/Data/work/svn/Sanguo2.0_build/Sanguo2.0/Client_Android/Assets";
    public static final String output_File = "/Volumes/Data/downloads/files.txt";

    public ArrayList<String> guids = new ArrayList<>();

    public ArrayList<String> fileList = new ArrayList<>();
    int i = 0;

    public static final void main(String args[]) {
        CheckFiles checkFiles = new CheckFiles();
        checkFiles.readGuids(source_dir);
        checkFiles.check(project_dir);
        checkFiles.output();

    }

    public void output() {
        StringBuffer sb = new StringBuffer();
        for (int j = 0; j < fileList.size(); j++) {
            sb.append(fileList.get(j));
            sb.append("\r\n");
        }
        sb.append("size = " + fileList.size());
        System.out.println(sb.toString());
        System.out.println("End" +fileList.size());
        UFile.writeFile(output_File, sb.toString());
    }

    public void check(String path) {
        File file = new File(path);
        if (file == null) {
            return;
        }
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (int i = 0; i < files.length; i++) {
                check(files[i].getPath());
            }
        } else if (file.getName().endsWith(".meta")) {
//            System.out.println(i++);
            String data = UFile.readString(path);
//            System.out.println(file.getName());
            for (int i = 0; i < guids.size(); i++) {
                String guid = guids.get(i);
                if (data.contains(guid)) {
                    guids.remove(i);
                    fileList.add(path);
                    return;
                }
            }
        }
    }

    public void readGuids(String path) {

        File[] files = new File(path).listFiles();
        for (int i = 0; i < files.length; i++) {
            String name = files[i].getName();
            if (!name.contains(".") && name.length() > 15) {
                guids.add(name);
            }
        }
    }
}